<?php


namespace app\common\library\task;

use app\common\model\ExamUserGrade;
use think\Exception;
use think\Lang;
use think\Log;
use think\Response;
use think\queue\Job;


class Task
{
    public function fire(Job $job, $data)
    {
        // 执行任务
        try {
            # 更新用户考试排名
            if (isset($data['type']) && $data['type'] == "rank") {
                foreach ($data['data'] as $k => $v) {
                    $rank = $k + 1;
                    ExamUserGrade::where('id', $v['id'])->update(['rank' => $rank]);
                }
            }
            $job->delete();
        } catch (Exception $exception) {
            Log::info("执行结果出错{$exception}" . json_encode($data, JSON_UNESCAPED_UNICODE));
        }
    }
}
